// formPackage/pages/team/performanceRanks/performanceRanks.js
import { getPerformanceRank } from "../../../../service/team_service"
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    themeStyle: "",
    rankThreeList: [
      // {
      //   avatar: "https://saas.img.ylyc.top/icon1111111.png",
      //   name: "延安器"
      // },
      // {
      //   avatar: "https://saas.img.ylyc.top/icon1111111.png",
      //   name: "延安器"
      // },
      // {
      //   avatar: "https://saas.img.ylyc.top/icon1111111.png",
      //   name: "延安器"
      // },
    ],
    rankOtherList: [
      // { type: 1 }, { type: 1 }, { type: 1 }, { type: 1 }, { type: 1 }, { type: 1 },
      // { type: 1 }, { type: 1 }, { type: 1 }, { type: 1 }, { type: 1 }, { type: 1 },
      // { type: 1 }, { type: 1 }, { type: 1 },
    ],
    page: 0,
    pageSize: 50,
    isEmpty: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getPerformanceRank();
  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (app.globalData.themeStyle) {
      this.setData({
        themeStyle: app.globalData.themeStyle
      })
    }
  },
  getPerformanceRank() {
    wx.showLoading();
    getPerformanceRank(this.data.page, this.data.pageSize).then(res => {
      wx.hideLoading();
      console.log("JJLog:业绩排行:" + JSON.stringify(res))
      if (res.code == 200) {
        if (res.data && res.data.length < 1) {
          this.setData({
            isEmpty: true
          })
        }
        if (res.data && res.data.length > 0 && res.data.length < 3) {
          this.setData({
            rankThreeList: res.data,
            rankOtherList: [],
          })
        }
        if (res.data && res.data.length > 2) {
          let arr = res.data;
          let otherArr = arr.splice(3);  //从第三个元素开始执行删除

          let threeArr = arr;
          console.log("JJLog:threeArr:" + JSON.stringify(threeArr));
          this.setData({
            rankThreeList: threeArr,
            rankOtherList: otherArr,
          })

        }
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: err || "查询失败",
        icon: "none"
      })
      console.error("JJLog:getPerformanceRank", err);
    })
  },





})